/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.dao.hibernate;

import com.minierp.dao.AlloBillItemDao;
import com.minierp.dao.hibernate.BaseDaoImpl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.HibernateCallback;

public class AlloBillItemDaoImpl extends BaseDaoImpl implements AlloBillItemDao {
	public List getList(long billId) {
		String sql = "from com.minierp.model.AlloBillItem s where s.billId="
				+ billId + " order by s.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getListWidthProd(long billId) {
		String sql = "select i,p from com.minierp.model.AlloBillItem i,com.minierp.model.Product p where i.productId=p.id and i.billId="
				+ billId + " order by i.id";
		return this.getHibernateTemplate().find(sql);
	}

	public List getStockList(long billId, long stoId) {
		String sql = "select s from com.minierp.model.AlloBillItem i,com.minierp.model.Stock s where i.productId=s.productId and s.storehouseId="
				+ stoId + " and i.billId=" + billId;
		return this.getHibernateTemplate().find(sql);
	}

	public int delete(final long id) {
		Object obj = this.getHibernateTemplate().execute(
				new HibernateCallback() {
					public Object doInHibernate(Session session)
							throws HibernateException, SQLException {
						String hql = "delete com.minierp.model.AlloBillItem where id=:id";
						return new Integer(session.createQuery(hql)
								.setLong("id", id).executeUpdate());
					}
				});
		return ((Integer) obj).intValue();
	}
}